package com.rookie.data.generate.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author rookie
 */

@Getter
@AllArgsConstructor
public enum ColumnRangeEnum {

    /**
     * 字段类型
     */
    TINYINT(-128, 127, "tinyint",1),

    SMALLINT(-32768, 32767, "smallint",1),

    INT(-100000, 999999, "int",1),

    MEDIUMINT(-100000, 999999, "mediumint",1),

    INTEGER(-100000, 999999, "integer",1),

    BIGINT(-1000000, 9999999, "bigint",1),

    DECIMAL(0, 999999, "decimal",2),

    FLOAT(-100000, 999999, "float",2),

    DOUBLE(-100000, 999999, "double",2),

    CHAR(1, 127, "char",3),


    VARCHAR(1, 1000, "varchar",3),

    TINYTEXT(1, 127, "tinytext",3),

    TEXT(1, 1000, "text",3),

    MEDIUMTEXT(1, 1000, "mediumtext",3),

    LONGTEXT(1, 1000, "longtext",3),

    /**
     * YYYY-MM-DD
     * 181
     */
    DATE(1, 44182, "date",4),

    /**
     * HH:MM:SS
     */
    TIME(1, 86400, "time",4),

    /**
     * YYYY
     */
    YEAR(1, 30, "year",4),

    /**
     * YYYY-MM-DD HH:MM:SS
     * 4 年
     */
    DATETIME(1, 2102400, "datetime",4),

    /**
     * 4 年
     */
    TIMESTAMP(1, 126144000, "timestamp",4);

    private final Integer min;

    private final Integer max;

    private final String name;
    /**
     * 类型 1：整形 2：浮点型 3:字符型 4：日期型
     */
    private final Integer type;


    public static ColumnRangeEnum getNumberEnum(String type) {
        if (StringUtils.isBlank(type)) {
            return null;
        }
        for (ColumnRangeEnum value : ColumnRangeEnum.values()) {
            if (value.getName().toUpperCase().equals(type)) {
                return value;
            }
        }
        return null;
    }
}